const path = require('path');
// const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const indexHtml = path.join(__dirname, "src", "index.html");
module.exports = {
  entry: ['./src/index.js', indexHtml],
  output: {
    filename: '[name].[hash].js',
    chunkFilename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'file-loader',
          'extract-loader',
          // 'style-loader',
          'css-loader'
        ]
      },
      {
        test: /\.(png|svg|jpg|gif)$/,
        use: ['file-loader']
      },
      // {
      //   test: /\.js$/,
      //   use: [
      //     'file-loader'
      //   ]
      // },
      {
        test: indexHtml,
        use: [
          {
            loader: "file-loader",
            options: {
              name: "[name]-dist.[ext]",
            },
          },
          {
            loader: "extract-loader",
          },
          {
            loader: "html-loader",
            options: {
              attrs: ["img:src", "link:href"],
              interpolate: true,
            },
          },
        ],
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(['dist']),
    // new HtmlWebpackPlugin({
    //   title: '代码分离2'
    // })
  ],
};
